package cn.edu.tju.elm.controller;

import cn.edu.tju.core.model.HttpResult;
import cn.edu.tju.core.model.ResultCodeEnum;
import cn.edu.tju.core.security.service.UserService;
import cn.edu.tju.elm.dto.FoodResponseDTO;
import cn.edu.tju.elm.mapper.FoodMapper;
import cn.edu.tju.elm.model.Food;
import cn.edu.tju.elm.service.FoodService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: MenuController
 * Package: cn.edu.tju.elm.controller
 * Description:
 *
 * @Author Niu Wenhang
 * @Create 2025/9/17 21:45
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/menu")
@Tag(name = "管理菜单")
public class MenuController {
    @Autowired
    private UserService userService;
    @Autowired
    private FoodService foodService;

    @Autowired
    private FoodMapper foodMapper;

    @GetMapping("/business/{id}")
    @Operation(summary = "查询店铺的菜单")
    public HttpResult<List<FoodResponseDTO>> getMenu(@PathVariable Long id) {
        try {
            List<Food> foods = foodService.getFoodsByBusinessId(id);
            List<FoodResponseDTO> responseDTOs = foodMapper.foodsToResponseDTOs(foods);
            return HttpResult.success(responseDTOs);
        } catch (Exception e) {
            return HttpResult.failure(ResultCodeEnum.SERVER_ERROR, "查询菜单失败: " + e.getMessage());
        }
    }

}
